﻿@using OASystem.Model;
@using OASystem.Controllers;
@{
    List<Departinfo> Departinfo1 = ViewBag.one as List<Departinfo>;
    List<Departinfo> Departinfo2 = ViewBag.two as List<Departinfo>;

}
<!doctype html>
<html>
<head>
    <meta charset="utf-8">

    <link rel="stylesheet" href="~/css/base.css" />
    <link rel="stylesheet" href="~/css/info-mgt.css" />
    <link rel="stylesheet" href="~/css/jquery.treetable.css" />
    <link rel="stylesheet" href="~/css/jquery.treetable.theme.default.css" />
    <style>
        .layui-layer-title {
            background: url(~/images/righttitlebig.png) repeat-x;
            font-weight: bold;
            color: #46647e;
            border: 1px solid #c1d3de;
            height: 33px;
            line-height: 33px;
        }

        .tabe_bot label {
            width: 70px;
            text-align: right;
            font-size: 14px;
            font-weight: 900;
            color: #46647e
        }

        .l_left {
            float: left
        }

        .tabe_bot input, .tabe_bot select {
            width: 180px;
            height: 30px;
            border-radius: 6px;
            margin: 0 20px 0 0;
            border: none;
            border: 1px #ccc solid
        }

        .tabe_btn {
            width: 60px;
            height: 30px;
            background-color: #68b86c;
            border: none;
            border-radius: 6px;
            color: #fff
        }
    </style>
    <title>部门管理</title>
</head>

<body>
    <div class="title"><h2>部门管理</h2></div>
    <div class="query">
        <div class="tabe_bot">
            <div class="l_left"><label>部门名称：</label><input type="text" id="name" placeholder="请输入部门名称"></div>


            <button class="tabe_btn" id="check">查询</button>
            <div class="clear"></div>
        </div>
    </div>
    <div class="table-operate ue-clear">
        <a href="~/Home/Part_tail" class="add" id="addpart">添加</a>


    </div>

    <div class="table-box">
        <table id="example-advanced" class="tableztree01">

            <tr class="thead_tr"><td style="padding-left: 10px;font-weight: bold">部门</td><td style="font-weight: bold">描述</td><td style="font-weight: bold">操作</td></tr>
            <tbody>
                @for (int i = 0; i < Departinfo1.Count; i++)
                    {
                        <tr data-tt-id="@Departinfo1[i].DepartId">

                            <td><span class="folder"></span>@Departinfo1[i].DepartName</td>
                            <td>@Departinfo1[i].Describe</td>
                            <td id="@Departinfo1[i].DepartId"><a href="~/Home/Part_tail">添加&nbsp;</a><a href="" class="del">删除&nbsp;</a><a href="#" class="edit" id="update">修改</a></td>
                        </tr>
                        if (Departinfo2 != null)
                        {
                            for (int j = 0; j < Departinfo2.Count; j++)
                            {
                                if (Departinfo2[j].DepartFatherId == Departinfo1[i].DepartId)
                                {
                                    <tr data-tt-id="@Departinfo1[i].DepartId+'-'@Departinfo2[j]" data-tt-parent-id="1" id="123">

                                        <td><span class="file"></span>@Departinfo2[j].DepartName</td>
                                        <td>@Departinfo2[j].Describe</td>
                                        <td id="@Departinfo2[j].DepartId"><a href="~/Home/Part_tail">添加&nbsp;</a><a href="" class="del">删除&nbsp;</a><a class="edit" id="update">修改</a></td>
                                    </tr>
                                }
                            }
                        }
                    }
            </tbody>
        </table>
    </div>
    <div class="pagination ue-clear"></div>
    <script type="text/javascript" src="~/js/jquery.js"></script>
    <script src="~/js/jquery.treetable.js"></script>


    <script>
        /* !function(){
             laydate.skin('molv');//切换皮肤，请查看skins下面皮肤库
             laydate({elem: '#demo'});//绑定元素
         }();*/
    </script>
    <script language="javascript">
        $("#example-advanced").treetable({ expandable: true });
    </script>
    <script src="~/js/layer_v2.1/layer/layer.js"></script>
    <script src="~/js/layer.js"></script>
    <script type="text/javascript">
        //部们管理查询点击事件
        $("#check").click(function () {
            var username = $("#name").val();
            $.ajax({
                type: "post",
                url: "/Part/QueryDepart?username=" + username,
                success: function (departinfos1) {
                    if (departinfos1 != null) {
                               $(".table-box").html("");

                        for (var i = 0; i < departinfos1.data.length; i++) {
                            $(".table-box").append('<table id="example-advanced" class="tableztree01"><tr class="thead_tr"><td style="padding-left: 10px;font-weight: bold">部门</td><td style="font-weight: bold">描述</td><td style="font-weight: bold">操作</td></tr>  <tbody>  <tr data-tt-id=' + departinfos1.data[i].DepartId + '><td><span class="folder"></span>' + departinfos1.data[i].DepartName + '</td><td>' + departinfos1.data[i].Describe + '</td><td><a href="/Home/Part_tail">添加&nbsp;</a><a href="" class="del">删除&nbsp;</a><a href="#" class="edit" id="update">修改</a></td></tr> </tbody> </table>');
                        }
                    }
                }
            });
        });
        ///编辑需要的传值
        $(".edit").click(function () {
            var id = $(this).parent().attr("id");
            $.ajax({
                type: "post",
                url: "/Part/Update?id=" + id,
                success: function (responseResult) {
                    if (responseResult.success) {
                        window.location.href = "/Home/Part_update";
                    } else {
                        layer.msg('发生异常!', { icon: 6, time: 1000 });
                    }
                }
            })
        })
        ///删除需要的传值
        $(".del").click(function () {
            var id = $(this).parent().attr("id");
            $.ajax({
                type: "post",
                url: "/Part/Update?id=" + id,
                success: function (responseResult) {
                    if (responseResult.success) {
                        window.location.href = "/Home/Part_delect";
                    } else {
                        layer.msg('发生异常!', { icon: 6, time: 1000 });
                    }
                }
            })
        })
    </script>
</body>
</html>
